package bc.swim2.ejb.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@NamedQueries({
		@NamedQuery(name = "Friendship.getFriendshipFromSenderIdAndReceiverId", query = "SELECT f FROM Friendship f WHERE f.senderId = :senderId AND f.receiverId = :receiverId"),
		@NamedQuery(name = "Friendship.getFriendshipRequestList", query = "SELECT f FROM Friendship f WHERE f.receiverId = :userId AND f.confirmed = FALSE"),
		@NamedQuery(name = "Friendship.getFriendList", query = "SELECT f FROM Friendship f WHERE (f.receiverId = :userId OR f.senderId = :userId) AND f.confirmed = TRUE"),
		@NamedQuery(name = "Friendship.setVisualizedTrueById", query = "UPDATE Friendship f SET f.visualized = TRUE WHERE f.id = :id"),
		@NamedQuery(name = "Friendship.getFriendshipState", query = "SELECT f FROM Friendship f WHERE (f.receiverId = :userId1 AND f.senderId = :userId2) OR (f.receiverId = :userId2 AND f.senderId = :userId1)"),
		@NamedQuery(name = "Friendship.getFriendshipsNotVisualized", query = "SELECT f FROM Friendship f WHERE f.senderId = :userId AND f.confirmed = TRUE AND f.visualized = FALSE") })
@Entity
@Table(name = "friendship")
public class Friendship implements Serializable {

	public Friendship(int senderId, int receiverId, boolean confirmed,
			boolean indirect) {
		super();
		this.senderId = senderId;
		this.receiverId = receiverId;
		this.confirmed = confirmed;
		this.indirect = indirect;
		this.visualized = false;
	}

	/**
	 * Default constructor
	 */
	public Friendship() {
	}

	private static final long serialVersionUID = -6687463819289127670L;

	/**
	 * Identification attribute for the entity Friendship
	 **/
	@Id
	@GeneratedValue
	@Column(name = "Id", nullable = false)
	int id;

	/**
	 * Attribute that represent the registered user that sent the request
	 */
	@Column(name = "SenderId", nullable = false)
	int senderId;
	/**
	 * Attribute that represent the user who has received the request
	 */
	@Column(name = "ReceiverId", nullable = false)
	int receiverId;

	/**
	 * Attribute that represent the status of the request (pending or accepted
	 * or denied)
	 */
	@Column(name = "Confirmed", nullable = false)
	boolean confirmed;

	/**
	 * Attribute that represent the status of the request (indirectly requested
	 * or directly requested)
	 */
	@Column(name = "Indirect", nullable = false)
	boolean indirect;

	/**
	 * Attribute that represent the status of the request (indirectly requested
	 * or directly requested)
	 */
	@Column(name = "Visualized", nullable = false)
	boolean visualized;

	/**
	 * Getter method for id
	 * 
	 * @return id
	 */
	public int getId() {
		return id;
	}

	/**
	 * Setter method for id
	 * 
	 * @param id
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Getter method for confirmed
	 * 
	 * @return confirmed
	 */
	public boolean getConfirmed() {
		return confirmed;
	}

	/**
	 * Setter method for confirmed
	 * 
	 * @param confirmed
	 */
	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}

	public boolean getIndirect() {
		return indirect;
	}

	public boolean getVisualized() {
		return visualized;
	}

	public void setVisualized(boolean visualized) {
		this.visualized = visualized;
	}

	public int getSenderId() {
		return senderId;
	}

	public void setSenderId(int senderId) {
		this.senderId = senderId;
	}

	public int getReceiverId() {
		return receiverId;
	}

	public void setReceiverId(int receiverId) {
		this.receiverId = receiverId;
	}
}
